﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Lawyer.DAL
{
	/// <summary>
	/// 数据访问类:CustomInfo
	/// </summary>
	public partial class CustomInfo
	{
		public CustomInfo()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string CustomID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from CustomInfo");
			strSql.Append(" where CustomID=@CustomID ");
			SqlParameter[] parameters = {
					new SqlParameter("@CustomID", SqlDbType.VarChar,36)};
			parameters[0].Value = CustomID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Lawyer.Model.CustomInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into CustomInfo(");
			strSql.Append("CustomID,Type,FullName,Email,Sex,Birthday,City,Telphone,Fax,Address,AvatarURL,Status,CreatedBy,CreatedDate,UpdatedBy,UpdatedDate)");
			strSql.Append(" values (");
			strSql.Append("@CustomID,@Type,@FullName,@Email,@Sex,@Birthday,@City,@Telphone,@Fax,@Address,@AvatarURL,@Status,@CreatedBy,@CreatedDate,@UpdatedBy,@UpdatedDate)");
			SqlParameter[] parameters = {
					new SqlParameter("@CustomID", SqlDbType.VarChar,36),
                    new SqlParameter("@Type", SqlDbType.Int,4),
					new SqlParameter("@FullName", SqlDbType.VarChar,50),
					new SqlParameter("@Email", SqlDbType.VarChar,50),
					new SqlParameter("@Sex", SqlDbType.VarChar,10),
					new SqlParameter("@Birthday", SqlDbType.DateTime),
					new SqlParameter("@City", SqlDbType.VarChar,50),
					new SqlParameter("@Telphone", SqlDbType.VarChar,50),
					new SqlParameter("@Fax", SqlDbType.VarChar,50),
					new SqlParameter("@Address", SqlDbType.VarChar,100),
					new SqlParameter("@AvatarURL", SqlDbType.VarChar,50),
					new SqlParameter("@Status", SqlDbType.Int,4),
					new SqlParameter("@CreatedBy", SqlDbType.VarChar,36),
					new SqlParameter("@CreatedDate", SqlDbType.DateTime),
					new SqlParameter("@UpdatedBy", SqlDbType.VarChar,36),
					new SqlParameter("@UpdatedDate", SqlDbType.DateTime)};
			parameters[0].Value = model.CustomID;
            parameters[1].Value = model.CustomType;
			parameters[2].Value = model.FullName;
			parameters[3].Value = model.Email;
			parameters[4].Value = model.Sex;
			parameters[5].Value = model.Birthday;
			parameters[6].Value = model.City;
			parameters[7].Value = model.Telphone;
			parameters[8].Value = model.Fax;
			parameters[9].Value = model.Address;
			parameters[10].Value = model.AvatarURL;
			parameters[11].Value = model.Status;
			parameters[12].Value = model.CreatedBy;
			parameters[13].Value = model.CreatedDate;
			parameters[14].Value = model.UpdatedBy;
			parameters[15].Value = model.UpdatedDate;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Lawyer.Model.CustomInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update CustomInfo set ");
            strSql.Append("Type=@Type,");
			strSql.Append("FullName=@FullName,");
			strSql.Append("Email=@Email,");
			strSql.Append("Sex=@Sex,");
			strSql.Append("Birthday=@Birthday,");
			strSql.Append("City=@City,");
			strSql.Append("Telphone=@Telphone,");
			strSql.Append("Fax=@Fax,");
			strSql.Append("Address=@Address,");
			strSql.Append("AvatarURL=@AvatarURL,");
			strSql.Append("Status=@Status,");
			strSql.Append("CreatedBy=@CreatedBy,");
			strSql.Append("CreatedDate=@CreatedDate,");
			strSql.Append("UpdatedBy=@UpdatedBy,");
			strSql.Append("UpdatedDate=@UpdatedDate");
			strSql.Append(" where CustomID=@CustomID ");
			SqlParameter[] parameters = {
                    new SqlParameter("@Type", SqlDbType.Int,4),
					new SqlParameter("@FullName", SqlDbType.VarChar,50),
					new SqlParameter("@Email", SqlDbType.VarChar,50),
					new SqlParameter("@Sex", SqlDbType.VarChar,10),
					new SqlParameter("@Birthday", SqlDbType.DateTime),
					new SqlParameter("@City", SqlDbType.VarChar,50),
					new SqlParameter("@Telphone", SqlDbType.VarChar,50),
					new SqlParameter("@Fax", SqlDbType.VarChar,50),
					new SqlParameter("@Address", SqlDbType.VarChar,100),
					new SqlParameter("@AvatarURL", SqlDbType.VarChar,50),
					new SqlParameter("@Status", SqlDbType.Int,4),
					new SqlParameter("@CreatedBy", SqlDbType.VarChar,36),
					new SqlParameter("@CreatedDate", SqlDbType.DateTime),
					new SqlParameter("@UpdatedBy", SqlDbType.VarChar,36),
					new SqlParameter("@UpdatedDate", SqlDbType.DateTime),
					new SqlParameter("@CustomID", SqlDbType.VarChar,36)};
            parameters[0].Value = model.CustomID;
            parameters[1].Value = model.CustomType;
            parameters[2].Value = model.FullName;
            parameters[3].Value = model.Email;
            parameters[4].Value = model.Sex;
            parameters[5].Value = model.Birthday;
            parameters[6].Value = model.City;
            parameters[7].Value = model.Telphone;
            parameters[8].Value = model.Fax;
            parameters[9].Value = model.Address;
            parameters[10].Value = model.AvatarURL;
            parameters[11].Value = model.Status;
            parameters[12].Value = model.CreatedBy;
            parameters[13].Value = model.CreatedDate;
            parameters[14].Value = model.UpdatedBy;
            parameters[15].Value = model.UpdatedDate;


			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string CustomID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from CustomInfo ");
			strSql.Append(" where CustomID=@CustomID ");
			SqlParameter[] parameters = {
					new SqlParameter("@CustomID", SqlDbType.VarChar,36)};
			parameters[0].Value = CustomID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string CustomIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from CustomInfo ");
			strSql.Append(" where CustomID in ("+CustomIDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Lawyer.Model.CustomInfo GetModel(string CustomID)
		{

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 CustomID,Type,FullName,Email,Sex,Birthday,City,Telphone,Fax,Address,AvatarURL,Status,CreatedBy,CreatedDate,UpdatedBy,UpdatedDate from CustomInfo ");
            strSql.Append(" where CustomID=@CustomID ");
            SqlParameter[] parameters = {
					new SqlParameter("@CustomID", SqlDbType.VarChar,36)};
            parameters[0].Value = CustomID;

            Model.CustomInfo model = new Model.CustomInfo();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["CustomID"] != null && ds.Tables[0].Rows[0]["CustomID"].ToString() != "")
                {
                    model.CustomID = ds.Tables[0].Rows[0]["CustomID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Type"] != null && ds.Tables[0].Rows[0]["Type"].ToString() != "")
                {
                    model.CustomType = int.Parse(ds.Tables[0].Rows[0]["Type"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FullName"] != null && ds.Tables[0].Rows[0]["FullName"].ToString() != "")
                {
                    model.FullName = ds.Tables[0].Rows[0]["FullName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Email"] != null && ds.Tables[0].Rows[0]["Email"].ToString() != "")
                {
                    model.Email = ds.Tables[0].Rows[0]["Email"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Sex"] != null && ds.Tables[0].Rows[0]["Sex"].ToString() != "")
                {
                    model.Sex = ds.Tables[0].Rows[0]["Sex"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Birthday"] != null && ds.Tables[0].Rows[0]["Birthday"].ToString() != "")
                {
                    model.Birthday = DateTime.Parse(ds.Tables[0].Rows[0]["Birthday"].ToString());
                }
                if (ds.Tables[0].Rows[0]["City"] != null && ds.Tables[0].Rows[0]["City"].ToString() != "")
                {
                    model.City = ds.Tables[0].Rows[0]["City"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Telphone"] != null && ds.Tables[0].Rows[0]["Telphone"].ToString() != "")
                {
                    model.Telphone = ds.Tables[0].Rows[0]["Telphone"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Fax"] != null && ds.Tables[0].Rows[0]["Fax"].ToString() != "")
                {
                    model.Fax = ds.Tables[0].Rows[0]["Fax"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Address"] != null && ds.Tables[0].Rows[0]["Address"].ToString() != "")
                {
                    model.Address = ds.Tables[0].Rows[0]["Address"].ToString();
                }
                if (ds.Tables[0].Rows[0]["AvatarURL"] != null && ds.Tables[0].Rows[0]["AvatarURL"].ToString() != "")
                {
                    model.AvatarURL = ds.Tables[0].Rows[0]["AvatarURL"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Status"] != null && ds.Tables[0].Rows[0]["Status"].ToString() != "")
                {
                    model.Status = int.Parse(ds.Tables[0].Rows[0]["Status"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CreatedBy"] != null && ds.Tables[0].Rows[0]["CreatedBy"].ToString() != "")
                {
                    model.CreatedBy = ds.Tables[0].Rows[0]["CreatedBy"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CreatedDate"] != null && ds.Tables[0].Rows[0]["CreatedDate"].ToString() != "")
                {
                    model.CreatedDate = DateTime.Parse(ds.Tables[0].Rows[0]["CreatedDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UpdatedBy"] != null && ds.Tables[0].Rows[0]["UpdatedBy"].ToString() != "")
                {
                    model.UpdatedBy = ds.Tables[0].Rows[0]["UpdatedBy"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UpdatedDate"] != null && ds.Tables[0].Rows[0]["UpdatedDate"].ToString() != "")
                {
                    model.UpdatedDate = DateTime.Parse(ds.Tables[0].Rows[0]["UpdatedDate"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select CustomID,Type,FullName,Email,Sex,Birthday,City,Telphone,Fax,Address,AvatarURL,Status,CreatedBy,CreatedDate,UpdatedBy,UpdatedDate ");
			strSql.Append(" FROM CustomInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" CustomID,Type,FullName,Email,Sex,Birthday,City,Telphone,Fax,Address,AvatarURL,Status,CreatedBy,CreatedDate,UpdatedBy,UpdatedDate ");
			strSql.Append(" FROM CustomInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "CustomInfo";
			parameters[1].Value = "CustomID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

